package com.jz.banner.screen.net.api

import com.lzy.okgo.OkGo
import com.lzy.okgo.cache.CacheMode
import com.lzy.okrx2.adapter.ObservableBody
import com.jz.banner.screen.bean.BaseBean
import com.jz.banner.screen.bean.BaseData
import com.jz.banner.screen.net.JsonConvert
import com.jz.banner.screen.utils.Params
import com.jz.banner.screen.utils.RxUtils
import io.reactivex.Observable
import java.util.*

object NormalApi {
    fun getData(params: SortedMap<String, Any?>, url: String?): Observable<BaseBean<BaseData>> {
        return OkGo
            .post<BaseBean<BaseData>>(url) //
            .cacheKey(url)
            .cacheMode(CacheMode.REQUEST_FAILED_READ_CACHE)
            .params(Params.getParams(params))
            .converter(object : JsonConvert<BaseBean<BaseData>>() {}) //
            .adapt(ObservableBody<BaseBean<BaseData>>()) //
            .compose(RxUtils.io())
    }
}